<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css">
    <link rel="stylesheet" href="/layuiadmin/style/login.css">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-name"></label>
                <input type="text" name="name" id="LAY-user-login-name" lay-verify="required" placeholder="用户名" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-oldpassword"></label>
                <input type="password" name="oldPwd" id="LAY-user-login-oldpassword" lay-verify="required" placeholder="老密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="newPwd" id="LAY-user-login-password" lay-verify="pass" placeholder="新密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function(){
        var $ = layui.$
            ,form = layui.form;
        form.render();
        //提交
        form.on('submit(LAY-user-reg-submit)', function(obj){
            var field = obj.field;
            //确认密码
            if(field.newPwd !== field.repass){
                return layer.msg('两次密码输入不一致');
            }
            $.ajax({
                url:"/manager/admin/psd",
                type:"PUT",
                data:JSON.stringify(field),
                dataType:"json",
                contentType: 'application/json; charset=UTF-8',
                success:function (res) {
                    top.layer.open({
                        content: res.msg,
                        closeBtn:false,
                        yes: function(index, layero){
                            top.layer.close(index);
                            if(res.code == 200){
                                top.location = "/index/logout"
                            }else if(res.code == 400){
                                top.layer.msg(res.msg, {
                                    offset: 't',
                                    anim: 6,
                                });
                            }else if(res.code == 403){
                                window.location.href = "/index/403"
                            }else if(res.code == -1){
                                top.layer.msg(res.msg, {
                                    offset: 't',
                                    anim: 6,
                                }, function(){
                                    top.window.location.href = "/index/login"
                                });
                            }else if(res.code == 500){
                                top.layer.msg(res.msg, {
                                    offset: 't',
                                    anim: 6,
                                }, function(){
                                    window.location.href = "/index/500"
                                });
                            }else{
                                top.layer.msg(res.msg, {
                                    offset: 't',
                                    anim: 6,
                                }, function(){
                                    window.location.href = "/index/500"
                                });
                            }
                        }
                    });
                }
            });
            return false;
        });
    });
</script>
</html>